package com.jha.develop.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.jha.common.utils.StringUtils;
import com.jha.common.core.page.TableDataInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.jha.develop.domain.bo.SysStudentBo;
import com.jha.develop.domain.vo.SysStudentVo;
import com.jha.develop.domain.SysStudent;

import com.jha.develop.mapper.SysStudentMapper;
import com.jha.develop.service.ISysStudentService;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 学生信息Service业务层处理
 *
 * @author JHA
 * @date 2025-11-13
 */
@RequiredArgsConstructor
@Service
public class SysStudentServiceImpl implements ISysStudentService {

    private final SysStudentMapper baseMapper;

    /**
     * 查询学生信息
     */
    @Override
    public SysStudentVo queryById(Long studentId){
        return baseMapper.selectSysStudentByStudentId(studentId);
    }


    /**
     * 查询学生信息列表
     */
    @Override
    public List<SysStudentVo> queryList(SysStudentBo bo) {
        return baseMapper.selectSysStudentList(bo);
    }


    /**
     * 新增学生信息
     */
    @Override
    public Boolean insertByBo(SysStudentBo bo) {
        SysStudent add = BeanUtil.toBean(bo, SysStudent.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setStudentId(add.getStudentId());
        }
        return flag;
    }

    /**
     * 修改学生信息
     */
    @Override
    public Boolean updateByBo(SysStudentBo bo) {
        SysStudent update = BeanUtil.toBean(bo, SysStudent.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(SysStudent entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除学生信息
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
